using System;
using System.Collections.Generic;
using System.Text;

namespace TST.SharePoint.Shared
{
    public class FieldNumber : Field
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        public FieldNumber()
        {
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="ID">The ID for the field.</param>
        public FieldNumber(string Id)
            : base(Id)
        {
        }

        /// <summary>
        /// Get the FieldType for the field URL.
        /// </summary>
        /// <returns></returns>
        public override FieldType FieldType
        {
            get
            {
                return FieldType.Number;
            }
        }

        /// <summary>
        /// Get the .NET datatype. Always returns double
        /// </summary>
        public override Type DataType
        {
            get
            {
                return typeof(double);
            }
        }

        public override object GetTypedValue(object value)
        {
            if (value == null)
                return null;
            double result;
            if (double.TryParse(value.ToString(), out result))
                return result;
            return null;
        }

        public override FilterType FilterType
        {
            get { return FilterType.Number; }
        }
    }
}
